#!/usr/bin/env python
# -*- coding:utf-8 -*-

"""
@author zyx
@since 2022/1/28 20:29
@file: c01_下载图片_方式1.py
"""
import requests

# 获取图片地址：通常为img标签的src属性值
img_src = 'http://img.itlun.cn/uploads/allimg/180527/1-1P52G43447-lp.jpg'
headers = {
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) '
                  'AppleWebKit/537.36 (KHTML, like Gecko) '
                  'Chrome/97.0.4692.71 Safari/537.36X-Requested-With: XMLHttpRequest'
}
# 对图片发起请求
response = requests.get(url=img_src, headers=headers)
# 获取图片数据:content返回的是二进制形式的响应数据
img_data = response.content
# 持久化存储
with open('./123.jpg', 'wb') as fp:
    fp.write(img_data)

